package com.boc.ewr.business.service.impl;

import com.boc.ewr.business.entity.AcctDtlClassA3;
import com.boc.ewr.business.entity.AcctDtlClassD;
import com.boc.ewr.business.mapper.AcctDtlClassA3Mapper;
import com.boc.ewr.business.service.IAcctDtlClassA3Service;
import com.boc.ewr.business.service.IAcctDtlClassDService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @Description: A3类账户明细
 * @Author: jeecg-boot
 * @Date:   2023-05-26
 * @Version: V1.0
 */
@Service
public class AcctDtlClassA3ServiceImpl extends ServiceImpl<AcctDtlClassA3Mapper, AcctDtlClassA3> implements IAcctDtlClassA3Service {

    @Autowired
    IAcctDtlClassDService acctDtlClassDService;

    @Autowired
    AcctDtlClassA3Mapper acctDtlClassA3Mapper;

    //产生数据
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createInfo() {
        List<AcctDtlClassA3> a3List = acctDtlClassA3Mapper.creatInfo();
        List<AcctDtlClassD> dList = acctDtlClassDService.list();

        //获取存在D类的账户
        Set<String> acctDList = dList.stream().map(AcctDtlClassD::getAcctNo).collect(Collectors.toSet());//D类

        List<String> acctList = new ArrayList<>(acctDList);
        //去掉D类（D1、D2、D3）
        List<AcctDtlClassA3> result = a3List.stream().filter(itm -> !acctList.contains(itm.getAccNo())).collect(Collectors.toList());

        saveBatch(result);
    }
}
